--[[
Author: your name
Date: 2020-12-01 11:04:22
LastEditTime: 2020-12-02 11:26:44
LastEditors: your name
Description: In User Settings Edit
FilePath: \Lua\View\HomeUI\UISaleConfirm.lua
--]]
require "Common/define"
require "Logic/Config"
require "Net/send_Msg"
require "Logic/EquipAttDecoder"


UISaleConfirm = {};
HelperFunc.SetUIEnv(UISaleConfirm)
local this = UISaleConfirm;

this.LuaBehaviour = nil;
this.transform = nil;
this.gameObject = nil;

this.msg_type  = Config.msg_type

--item数据
this.itemData = nil;
--定义控件
this.label_equiptips = nil;
this.label_propstips = nil;
this.label_manyequiptips = nil;

this.btn_confirm = nil;
this.btn_cancel = nil;


function UISaleConfirm.Init(data) 
    itemData = data;    
	
	local name = getUIName(PanelNames.UISaleConfirm);
    panelMgr:ShowUI(name, this.OnCreate,Config.useLocalUI);    
end

function UISaleConfirm.OnCreate(obj)
	gameObject = obj;
    transform = obj.transform;
	LuaBehaviour = transform:GetComponent('LuaBehaviour');

	label_equiptips=transform:Find("frame/EquipTips").gameObject;
    label_propstips=transform:Find("frame/PropsTips").gameObject;
	label_manyequiptips=transform:Find("frame/ManyEquipTips").gameObject;
	
	btn_confirm=transform:Find("ConfirmBtn").gameObject;
	btn_cancel=transform:Find("CancelBtn").gameObject;

	LuaBehaviour:AddClick(btn_confirm,this.OnSellEquip);
	LuaBehaviour:AddClick(btn_cancel,this.OnCloseClick);
	this.ShowLabels();
	 
end

function UISaleConfirm.ShowLabels()
	gameObject:SetActive(true);				
	local count=itemData.packNum;
	print("物品数量："..count);

	local qIcon = itemData.color;
    local color =  G.dataTable["ItemQualityConfig"]["ColorCode"][qIcon];
    color = string.gsub(color,"0x","#");
	print("物品颜色："..color);

	if count~=1 then
		label_equiptips:SetActive(false);
		label_propstips:SetActive(true);
		label_manyequiptips:SetActive(false);
		label_propstips:GetComponent("Text").text = "售出后无法购回,\n您是否出售<color="..color..">"..itemData.name.."</color>x"..count;
	else	
		label_equiptips:SetActive(true);
		label_propstips:SetActive(false);
		label_manyequiptips:SetActive(false);
		label_equiptips:GetComponent("Text").text = "售出后无法购回,您是否出售<color="..color..">"..itemData.name.."</color>";
	end   
end

function UISaleConfirm.OnSellEquip(obj)
	if itemData.ptype > ItemType.ITYPE_Lcha or itemData.ptype < ItemType.PTYPE_Weapon then
		UIItemInfo.OnSellClick(obj);
		this.OnCloseClick();
	else
		UIEquipInfo.OnSellEquip(obj);
		this.OnCloseClick();
	end
end


function UISaleConfirm.OnCloseClick(obj)  
    init = false;

    panelMgr:CloseUI("UISaleConfirm",true);       

end


return UISaleConfirm;